<?php
/**
 * Author: bedirhan
 */

    require_once('genclude.php'); // initialization
    require_once "PPopulator.php"; // parameter population easifier
    require_once "Anonymizer.php"; // anonmyzfying and raw data normalization
    require_once "MSALServiceDB.php"; // db operations

    if(!isset($delimiter))
        $delimiter = "\r\n";

    $targetDate = PPopulator::getTargetDate($_SESSION["currentdate"]);

    // when the target date changes, then reinitialize the returned row set index to 0
    if(strcmp($targetDate,$_SESSION["currentdate"]) != 0 )
        $_SESSION["setindex"] = 0;

    // update the current date for the session
    $_SESSION["currentdate"] = $targetDate;

    $_SESSION["setindex"] = PPopulator::getSetIndex($_SESSION["setindex"]);

    // fetch the rows
    $rows = MSALServiceDB::getMSALRows($targetDate, $_SESSION["setindex"]);

    // anonymize the data
    Anonymizer::anonymize($rows);
    
    // SourceIP, AuditLogTime from $db_auditlog_table
    // Severity, Msg, RuleID from $db_alerts_table
    //echo "AuditLogID\tSourceIP\tAuditLogTime\tSeverity\tMsg\tRuleID";
    //echo $delimiter;
    for($i=0; $i < count($rows); $i++){
        $arow = $rows[$i];
            echo $arow['AuditLogID'] . "\t" . $arow['SourceIP'] . "\t" . $arow['AuditLogTime'] . "\t" . $arow['Severity'] . "\t" .  $arow['Msg'] . "\t" .  $arow['RuleID'];
        echo $delimiter;
    }

?>
